package com.frame.exception

import org.apache.shiro.authz.AuthorizationException
import org.apache.shiro.authz.UnauthorizedException
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import javax.ws.rs.core.Response
import javax.ws.rs.ext.ExceptionMapper
import javax.ws.rs.ext.Provider

/**
 * Created by three on 14-8-1.
 */
@Provider
class ShiroExceptionMapper implements ExceptionMapper<AuthorizationException> {

    private Logger log = LoggerFactory.getLogger(ShiroExceptionMapper.class);

    @Override
    public Response toResponse(AuthorizationException exception) {
        log.info("shiro认证错误", exception);
        return Response.status(Response.Status.UNAUTHORIZED).entity("shiro 认证错误").
                type("text/plain").build();
    }

}
